package com.ysd.lis.service.sta.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.dto.sta.StaDto;
import com.ysd.lis.dto.sta.StaParam;
import com.ysd.lis.entity.sta.StaOthResultDict;
import com.ysd.lis.mapper.sta.StaOthResultDictMapper;
import com.ysd.lis.service.sta.StaOthResultDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * cold_chain.sys_module 服务实现类
 * </p>
 *
 * @author prs
 * @since 2024-12-27
 */
@Service
public class StaOthResultDictServiceImpl extends ServiceImpl<StaOthResultDictMapper, StaOthResultDict> implements StaOthResultDictService {

    @Autowired
    StaOthResultDictMapper staOthResultDictMapper;

    @Override
    public Result findStaOthResultDictList(StaParam pageParam) {
        MPJLambdaWrapper<StaOthResultDict> lambdaQueryWrapper = new MPJLambdaWrapper<>();
        lambdaQueryWrapper.eq(StaOthResultDict::getDelFlag, 0);
        if (StringUtils.isNotBlank(pageParam.getSeachValue())) {
            lambdaQueryWrapper.and(wrapper -> wrapper.like(StaOthResultDict::getOthResultNo, pageParam.getSeachValue())
                    .or().like(StaOthResultDict::getOthResultNa, pageParam.getSeachValue())
                    .or().like(StaOthResultDict::getInputCode,pageParam.getSeachValue()));
        }

        lambdaQueryWrapper.orderByAsc(StaOthResultDict::getCreateTime);
        List<StaOthResultDict> supplierPage = staOthResultDictMapper.selectList( lambdaQueryWrapper);
        return Result.succ(1, "查询成功", supplierPage);
    }

    @Override
    public Result addStaOthResultDict(StaOthResultDict staOthResultDict) {
        int insert = staOthResultDictMapper.insert(staOthResultDict);
        if(insert>0){
            return Result.succ(1,"添加成功",staOthResultDict);
        }else {
            return Result.fail(400,"添加失败","");
        }
    }

    @Override
    public Result editStaOthResultDict(StaOthResultDict supplier) {
        int updateById = staOthResultDictMapper.updateById(supplier);
        if(updateById>0){
            return Result.succ(1,"提交成功",supplier);
        }else {
            return Result.fail(400,"修改失败","");
        }
    }

    @Override
    public Result batchDeleteStaOthResultDictList(StaDto dto) {
        List<StaOthResultDict> supplierList = dto.getStaOthResultDictList();
        List<String> ids = supplierList.stream().map(StaOthResultDict::getId).collect(Collectors.toList());

        boolean b = this.removeByIds(ids);
        if(b){
            return Result.succ(1, "删除成功", null);
        }else {
            return Result.fail(400,"删除失败","");
        }
    }


    @Override
    public Result findStaOthResultDictPageList(StaParam pageParam) {
        Page<StaOthResultDict> page = new Page<>();
        page.setCurrent(pageParam.getPageIndex());
        page.setSize(pageParam.getPageSize());
        MPJLambdaWrapper<StaOthResultDict> lambdaQueryWrapper = new MPJLambdaWrapper<>();
        lambdaQueryWrapper.eq(StaOthResultDict::getDelFlag, 0);
        if (StringUtils.isNotBlank(pageParam.getSeachValue())) {
            lambdaQueryWrapper.and(wrapper -> wrapper.like(StaOthResultDict::getOthResultNo, pageParam.getSeachValue())
                    .or().like(StaOthResultDict::getOthResultNa, pageParam.getSeachValue())
                    .or().like(StaOthResultDict::getInputCode,pageParam.getSeachValue()));
        }

        lambdaQueryWrapper.orderByAsc(StaOthResultDict::getCreateTime);
        Page<StaOthResultDict> supplierPage = staOthResultDictMapper.selectPage(page, lambdaQueryWrapper);
        return Result.succ(1, "查询成功", supplierPage);
    }
}
